#include "settingform.h"
#include "ui_settingform.h"
#include <QDebug>

static SettingForm *inst = nullptr;

SettingForm::SettingForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SettingForm)
{
    ui->setupUi(this);
    this->model = new QStandardItemModel; //创建一个标准的条目模型
    this->ui->tableView->setModel(model);


    this->model->setHorizontalHeaderItem(0, new QStandardItem("插件名字") );
    this->model->setHorizontalHeaderItem(1, new QStandardItem("插件版本号"));
    this->model->setHorizontalHeaderItem(2, new QStandardItem("插件接口类型"));
    this->model->setHorizontalHeaderItem(3, new QStandardItem("插件接口版本号"));

    //设置列的宽度
    this->ui->tableView->setColumnWidth(0, 150);    //插件名字
    this->ui->tableView->setColumnWidth(1, 150);    //插件版本号
    this->ui->tableView->setColumnWidth(2, 150);    //插件接口号
    this->ui->tableView->setColumnWidth(3, 150);    //插件接口号
}

SettingForm::~SettingForm()
{
    delete ui;
}

SettingForm *SettingForm::instances()
{
    qDebug() << "getSetting";
    if( inst == nullptr )
    {
        qDebug() << "inst is null, and new SettingForm()";
        inst = new SettingForm();
    }
    return inst;
}

int SettingForm::AddLibInfo(int index, PluginInfo *info)
{
    /*setItem设置条目栏中的一个格子的信息*/
    this->model->setItem(index, 0, new QStandardItem(info->name) );
    this->model->setItem(index, 1, new QStandardItem(info->pluginVersion ) );
    this->model->setItem(index, 2, new QStandardItem( PluginDefine::mapType(info->interfaceType) ));
    this->model->setItem(index, 3, new QStandardItem( QString::number(info->interfaceVersion) ));
    return 0;
}
